#include "imagemodel.h"
#include <QHeaderView>

ImageModel::ImageModel(QImage img){
    setImage(img);
}

void ImageModel::setImage(QImage img){
    image = img;
    height = img.height();
    width = img.width();
}

int ImageModel::columnCount ( const QModelIndex & parent) const{
    return(width);
}

QVariant ImageModel::data ( const QModelIndex & index, int role) const{
    if(!role)
        return(qRed(image.pixel(index.row(),index.column())));
    return(QVariant());
}

QModelIndex ImageModel::index ( int row, int column, const QModelIndex & parent) const{
    return(createIndex(row,column,row*width+height));
}

QModelIndex ImageModel::parent ( const QModelIndex & index ) const{
    return(QModelIndex());
}

int ImageModel::rowCount ( const QModelIndex & parent) const{
    return(height);
}

ImageTabel::ImageTabel(QWidget* parent):QTableView(parent){
    this->horizontalHeader()->setDefaultSectionSize(25);
    this->verticalHeader()->setDefaultSectionSize(25);
}
